package com.hxd.otc.module.convenience.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.convenience.adapter.ConvenienceAdapter;
import com.hxd.otc.module.convenience.bean.ConvenienceBannerBean;
import com.hxd.otc.module.convenience.bean.RefuelingServiceBean;
import com.hxd.otc.module.convenience.contract.ConvenienceContract;
import com.hxd.otc.module.convenience.model.ConvenienceModel;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * Created by lzy on 2018/12/14 0014.
 * description ${便民服务Presenter}
 */
public class ConveniencePresenter extends BaseRecyclerPresenter<ConvenienceContract.IView, ConvenienceAdapter, RefuelingServiceBean> implements ConvenienceContract.IPresenter {

    private final ConvenienceModel mConvenienceModel;

    public ConveniencePresenter(ConvenienceContract.IView iView) {
        super(iView);
        mConvenienceModel = ConvenienceModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mConvenienceModel.getModuleList("0", new BaseObserver<ArrayList<RefuelingServiceBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<RefuelingServiceBean> refuelingServiceBeans) {
                onLoadDataSuccess(isRefresh, refuelingServiceBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<ArrayList<RefuelingServiceBean>>>bindAutoDispose());
    }

    @Override
    public void getBannerList() {
        mConvenienceModel.getBannerList(1, new BaseObserver<ArrayList<ConvenienceBannerBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<ConvenienceBannerBean> convenienceBannerBeans) {
                mView.getBannerListSuccess(convenienceBannerBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.getBannerListFail(errMessage);
            }
        }, mView.<BaseBean<ArrayList<ConvenienceBannerBean>>>bindAutoDispose());
    }

    @Override
    public void bannerUpdate(String bannerId) {
        mConvenienceModel.bannerUpdate(bannerId, new BaseObserver<Object>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
            }
        }, mView.<BaseBean<Object>>bindAutoDispose());
    }
}
